package com.stars.controller.pshow;

import com.stars.entity.dto.pshow.PShowProductDTO;
import com.stars.services.pshow.PShowProductConfigServices;
import com.stars.entity.pshow.PShowProductEntity;
import com.stars.services.pshow.PShowProductAccessServices;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.stars.common.annotation.Log;
import com.stars.common.base.BaseMsg;
import com.stars.common.ObjectCopyUtils;
import com.stars.common.base.BaseConstant;
import com.stars.common.base.ResultMsg;
import com.stars.controller.BaseController;
import com.stars.common.enums.OperationType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import com.stars.common.valid.AddView;
import com.stars.common.valid.UpdateView;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.multipart.MultipartFile;
import com.stars.common.easypoi.ExcelUtils;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * @Title: 仓库管理 mybatis dao
 * @author 肖伟
 * @date 2020-01-04
 * @version V1.0
 *
 */
@Slf4j
@RestController
@RequestMapping("/pShowProductCtl")
@Api(tags ="仓库管理")
public class PShowProductCtl extends BaseController{
   @Autowired
   private PShowProductAccessServices  pShowProductAccessServicesImpl;
   @Autowired
   private PShowProductConfigServices  pShowProductConfigServicesImpl;

   /**
   *  分页查询
   * @param pageNum 起始页
   * @param pageSize 大小
   * @return 分页数据
   * @throws Exception
   */
   @GetMapping("/pageList")
   @ApiOperation(value = "仓库管理"+BaseMsg.MODULAR_PAGE,notes ="仓库管理"+ BaseMsg.MODULAR_PAGE)
   @Log(detail = "仓库管理"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
   public PageInfo<PShowProductDTO> pagePShowProductList(Integer pageNum, Integer pageSize, PShowProductDTO dto,HttpServletRequest request) throws Exception{
  
        return pShowProductAccessServicesImpl.pageList(pageNum,pageSize,dto);

   }
    /**
    * 保存
    * @param entityName
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "仓库管理"+ BaseMsg.MODULAR_ADD,notes = "仓库管理"+BaseMsg.MODULAR_ADD)
    @Log(detail = "仓库管理"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    public ResultMsg addPShowProduct(@Validated({AddView.class}) PShowProductEntity entityName,HttpServletRequest request) throws Exception{
        setAddBase(entityName,request,null);
        return pShowProductConfigServicesImpl.insertSelective(entityName);
    }
    /**
    * 更新
    * @param updateEntityDto
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/update")
    @ApiOperation(value = "仓库管理"+ BaseMsg.MODULAR_UPDATE,notes = "仓库管理"+ BaseMsg.MODULAR_ADD)
    @Log(detail = "仓库管理"+ BaseMsg.MODULAR_UPDATE,operationType = OperationType.UPDATE)
    public ResultMsg updatePShowProduct(@Validated({UpdateView.class}) PShowProductEntity updateEntityDto,HttpServletRequest request) throws Exception{
        PShowProductEntity entity = pShowProductAccessServicesImpl.selectById(updateEntityDto.getId());
        ObjectCopyUtils.copyPropertiesIf(updateEntityDto,entity, BaseConstant.UPDATE);
        setUpdateBase(entity,request);
        return pShowProductConfigServicesImpl.updateSelectiveById(entity);
    }
	 /**
     * 删除
     * @param ids
     * @return 成功失败
     * @throws Exception
     */
     @PostMapping(value = "/delById")
     @ApiOperation(value = "仓库管理"+BaseMsg.MODULAR_DEL,notes ="仓库管理"+BaseMsg.MODULAR_DEL)
     @Log(detail ="仓库管理"+BaseMsg.MODULAR_DEL,operationType = OperationType.DELETE)
     public ResultMsg delPShowProductById(String ids) throws Exception{
        return pShowProductConfigServicesImpl.deleteByIds(ids.split(BaseConstant.SPOT));
     }
    /**
    * 根据id查询
    * @param id
    * @return 查询对象
    * @throws Exception
    */
    @GetMapping(value = "/findById")
    @ApiOperation(value = "仓库管理"+ BaseMsg.MODULAR_FIND_ID,notes = "仓库管理"+BaseMsg.MODULAR_FIND_ID)
    @Log(detail = "仓库管理"+ BaseMsg.MODULAR_FIND_ID,operationType = OperationType.SELECT)
    public ResultMsg findPShowProductById(String id) throws Exception{
        PShowProductEntity entityName = pShowProductAccessServicesImpl.selectById(id);
         return ResultMsg.success(entityName);
    }

    

	 /**
     * 导出
     * @param dto 查询条件
     * @param response
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/exportList")
    @ApiOperation(value = "仓库管理",notes ="仓库管理"+BaseMsg.MODULAR_SEARCH)
    @Log(detail ="仓库管理",operationType = OperationType.SELECT)
     public ResultMsg exportList(PShowProductDTO dto,HttpServletResponse response)throws Exception{
         // 模拟从数据库获取需要导出的数据
         PageInfo<PShowProductDTO> personList = pShowProductAccessServicesImpl.pageList(1,2000,dto);
         // 导出操作
         ExcelUtils.exportExcel(personList.getList(), "仓库管理"+"导出", "仓库管理", PShowProductDTO.class, "仓库管理"+".xls", response);
        return ResultMsg.success();
     }
    /**
     * 导入
     * @param file 查询条件
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/importExcel")
    @ApiOperation(value = "仓库管理",notes ="仓库管理"+BaseMsg.MODULAR_SEARCH)
    @Log(detail ="仓库管理",operationType = OperationType.SELECT)
    public ResultMsg importExcel(@RequestParam("file") MultipartFile file)throws Exception{
        // 导入操作
        List<PShowProductEntity> importList = ExcelUtils.importExcel(file, 0, 1, PShowProductEntity.class);
		return pShowProductConfigServicesImpl.addImportExcel(importList,new ResultMsg()); 
    }




}